package ae.pcfc.cldos.online.common.clddb.dao.provider;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import ae.pcfc.cldos.online.common.clddb.dao.FnpParamMapperDAO;
import ae.pcfc.cldos.online.common.clddb.domain.FnpParamMapper;
import ae.pcfc.cldos.online.common.dao.GenericDAO;

/**
 * @author akhader
 * 
 */
@Repository
public class FnpParamMapperDAOImpl extends GenericDAO implements FnpParamMapperDAO {

	/**
	 * @param serviceCode
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<FnpParamMapper> getParamMappingByServiceId(String serviceId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FnpParamMapper.class);
		criteria.add(Restrictions.eq(FnpParamMapper.__FPM_SERVICE_ID,serviceId));
		return (List<FnpParamMapper>) getListByCriteria(criteria);
	}
	
	/**
	 * @param fnpParamMappers
	 * @param serviceIds
	 */
	public void saveParamMapping(List<FnpParamMapper> fnpParamMappers, List<String> serviceIds){
		for(String serviceId : serviceIds){
			List<FnpParamMapper> paramMapping = getParamMappingByServiceId(serviceId);
			if(paramMapping!=null && paramMapping.size()!=0){
				deleteAll(paramMapping);
			}
			
		}
		for(FnpParamMapper fnpParamMapper:fnpParamMappers){
			saveOrUpdate(fnpParamMapper);
		}
	}
	/**
	 * @param serviceId
	 */
	public void deleteAll(String serviceId){
		deleteAll(getParamMappingByServiceId(serviceId));
	}
	
}
